package com.oddpointcc.szpt.accounting.service;

import com.oddpointcc.szpt.accounting.pojo.Book;
import org.springframework.stereotype.Service;

import java.util.*;


@Service
public class BookService {

    private List<String> bookNames = Arrays.asList("Liunx内核与实现","算法导论","数据结构与算法","编程原理","高性能MySQL","深入理解计算机操作系统");
    /**
     * 随机选取五本书进行初始化
     * @return
     */
    public List<Book> findBooks(){
        List<Book> bookList = new ArrayList<>();
        Collections.shuffle(bookNames);
        bookNames.stream().limit(5).distinct().forEach(s -> {
            Book book = new Book(bookNames.indexOf(s), s, (double) Math.round(new Random().nextDouble()*10000)/100);
            bookList.add(book);
        });
        return bookList;
    }

}
